package io.renren.modules.app.service.impl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.app.service.ShopinfoService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zheok.testing.dao.ShopinfoDao;
import com.zheok.testing.entity.ShopinfoEntity;


@Service("shopinfoService")
public class ShopinfoServiceImpl extends ServiceImpl<ShopinfoDao, ShopinfoEntity> implements ShopinfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<ShopinfoEntity> wrapper = new QueryWrapper<>();

        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        if(!userEntity.getUsername().equals("admin")){
            wrapper.lambda().eq(ShopinfoEntity::getShopId,userEntity.getUserId());
        }
        IPage<ShopinfoEntity> page = this.page(
                new Query<ShopinfoEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void saveinfo(ShopinfoEntity shopinfo) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        shopinfo.setShopId(userEntity.getUserId());
        this.saveOrUpdate(shopinfo);

    }

}